from django.db import models
from login.models import User


# Create your models here.

class UserIntro(models.Model):
    """用户简介模型"""
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='所属用户', related_name='user_intro')

    TO_BE_EXAMINED = 0
    EXAMINED = 1
    STATE_CHOICES = [
        (TO_BE_EXAMINED, '待审核'),
        (EXAMINED, '审核通过'),
    ]
    state = models.SmallIntegerField(verbose_name='状态', choices=STATE_CHOICES, default=EXAMINED, null=False)

    intro = models.TextField(blank=True, null=True, verbose_name='介绍信息')

    # intro_image = models.CharField(verbose_name='介绍图片', max_length=255)

    class Meta:
        db_table = 'user_info'
        verbose_name = verbose_name_plural = '用户简介'

    def __str__(self):
        if len(self.intro) > 20:
            return self.intro[:20] + '...'
        else:
            return self.intro


class Complaint(models.Model):
    # 投诉人
    complainant = models.ForeignKey(User, on_delete=models.CASCADE, related_name='my_complaints')
    # 投诉人
    respondent = models.ForeignKey(User, on_delete=models.CASCADE, related_name='complaints_to_me')
    # 状态
    PENDING = 0
    SUCCESS = 1
    FAILURE = 2
    STATE_CHOICES = [
        (PENDING, '待受理'),
        (SUCCESS, '投诉成功'),
        (FAILURE, '投诉失败'),
    ]
    state = models.SmallIntegerField(verbose_name='状态', choices=STATE_CHOICES, default=PENDING, null=False)

    class Meta:
        db_table = 'complaint'
        verbose_name = verbose_name_plural = '投诉信息'

    def __str__(self):
        return self.complainant + ' to ' + self.respondent
